/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.business.router.core.repository.mapper;


import info.peigen.hotpot.business.router.core.repository.entity.ReceiptCardEntity;
import info.peigen.hotpot.business.router.facade.enums.ChannelCode;
import info.peigen.hotpot.common.core.enums.Currency;
import info.peigen.hotpot.component.data.repository.beetlsql.mapper.AbstractBeetlSqlMapper;
import org.beetl.sql.mapper.annotation.Select;
import org.beetl.sql.mapper.annotation.Sql;
import org.beetl.sql.mapper.annotation.Update;

import java.util.List;

/**
 * <b>(ReceiptCardMapper)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2021/8/12
 */
@SuppressWarnings({"AlibabaAbstractMethodOrInterfaceMethodMustUseJavadoc", "unused"})
public interface ReceiptCardMapper extends AbstractBeetlSqlMapper<ReceiptCardEntity> {
    @Sql("select * from router_receipt_card where card_id = ?")
    @Select
    ReceiptCardEntity findByCardId(String cardId);

    @Sql("select * from router_receipt_card where id=(select max(id) from router_receipt_card where code = ? and status IN('Allocated', 'Recycled'))")

    @Select
    ReceiptCardEntity findLastAllocatedAndRecycledByCode(ChannelCode code);

    @Sql("select * from router_receipt_card where code = ?")
    @Select
    List<ReceiptCardEntity> listByCode(ChannelCode code);

    @Sql("delete from router_receipt_card where card_id = ?")
    @Update
    void deleteByCardId(String cardId);

    @Sql("delete from router_receipt_card where code = ?")
    @Update
    void deleteByCode(ChannelCode code);


    @Sql("delete from router_receipt_card where card_name = ?")
    @Update
    void deleteByCardName(String cardName);

    @Sql("delete from router_receipt_card where card_name = ? and code = ? and currency  = ?")
    @Update
    void deleteByCardNameAndCodeAndCurrency(String cardName, ChannelCode code, Currency currency);
}